Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

SUS-2571 | update the memcache when User::setNewtalk() is called #13507

Merged
merged 2 commits into from
Aug 8, 2017

Conversation

macbre
Copy link
Contributor

@macbre macbre commented Aug 8, 2017

https://wikia-inc.atlassian.net/browse/SUS-2571

This way we avoid subsequent database query to a master. Instead, we just get the updated value from the memcache.

Cache miss

> $u = User::newFromName('Macbre'); var_dump( $u->getNewtalk() );
...
memcached: get(dev-macbre-plpoznan:user:id:119245)
memcached: MemCache: sock i:0; got dev-macbre-plpoznan:user:id:119245
memcached: get(dev-macbre-wikicities:user_touched:v1:119245)
memcached: MemCache: sock i:0; got dev-macbre-wikicities:user_touched:v1:119245
User: got user 119245 from cache

memcached: get(dev-macbre-plpoznan:newtalk:user:119245)
Query plpoznan (DB user: wikia_maint) (11) (slave): SELECT /* User::checkNewtalk CommandLineInc - a562a3b7-2989-4663-a2b2-30c0dacfc0b3 */  user_id  FROM `user_newtalk`  WHERE user_id = '119245'  LIMIT 1  

memcached: set dev-macbre-plpoznan:newtalk:user:119245 (STORED)

/usr/wikia/source/deploytools/18879/src/maintenance/eval.php(88) : eval()'d code:1:
bool(false)

Update the new talk state

> $u = User::newFromName('Macbre'); $u->setNewtalk( true ); var_dump( $u->getNewtalk() );
...
DatabaseBase::query: Writes done: INSERT IGNORE INTO `user_newtalk` (user_id) VALUES ('119245')
Query plpoznan (DB user: wikia_maint) (10) (master): INSERT /* User::updateNewtalk CommandLineInc - e065dd1b-cc5d-4cdf-8abf-f9043e0626ee */ IGNORE INTO `user_newtalk` (user_id) VALUES ('119245')
User::updateNewtalk: set on (user_id, 119245)

memcached: set dev-macbre-plpoznan:newtalk:user:119245 (STORED)
memcached: set dev-macbre-wikicities:user-quicktouched:id:119245 (STORED)
memcached: MemCache: delete dev-macbre-plpoznan:user:id:119245 (DELETED)
...
/usr/wikia/source/deploytools/18879/src/maintenance/eval.php(88) : eval()'d code:1:
bool(true)

The numbers

This change should remove a great part of 146,618 queries that we make daily from User::getNewtalk method to database master nodes (out of 2,4 mm that we make daily when handling GET requests).

This way we avoid subsequent database query to a master. Instead, we just get the updated value from the memcache.
@macbre macbre added the sus label Aug 8, 2017
@macbre macbre merged commit 782494b into dev Aug 8, 2017
@macbre macbre deleted the SUS-2571-cache-new-talks branch August 8, 2017 13:54
@macbre
Copy link
Contributor Author

macbre commented May 25, 2018

The amount of User::checkNewtalk queries dropped significantly as well:

before the fix - 800k queries were made each hour (always to master)
after the fix - 180k queries (they all hit slaves now) - drop by 78%.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants